// (C) Copyright 2002-2007 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//

//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "CEdSSgetFilter.h"
#include "CDocReactor.h"

//-----------------------------------------------------------------------------
#define szRDS _RXST("")

AcArray<AcString> commands;
AcArray<AcRxClass *> classNames;
std::map<AcApDocument *, CEdSSgetFilter *> reactors;
CDocReactor *pReactor;

void Initialize()
{
//////////////////////////////////////////////////////////////////////////
//				Patterns list of disabled commands
//////////////////////////////////////////////////////////////////////////
	commands.append(_T("MOVE"));
	commands.append(_T("TRIM"));
	commands.append(_T("BREAK"));
	commands.append(_T("EXTEND"));
	commands.append(_T("STRETCH"));
	commands.append(_T("EXPLODE"));
	commands.append(_T("LENGTHEN"));
//////////////////////////////////////////////////////////////////////////
//				List of checked classes
//////////////////////////////////////////////////////////////////////////
	classNames.append(AcDbLine::desc());
	classNames.append(AcDbCircle::desc());
	classNames.append(AcDbArc::desc());
//	classNames.append(MyCustomEntityClass::desc());
}

bool isCheckedClass(AcRxClass *rxclass, bool isCheckedDerived)
{
	if (!rxclass) return false;
	if (classNames.isEmpty()) return true; // If there are no classes - all classes are checked
	for (int i=0; i < classNames.length(); i++) {
		if (_wcsicmp(rxclass->name(),classNames[i]->name()) == 0) return true;
		if (isCheckedDerived && rxclass->isDerivedFrom(classNames[i])) return true;
	}
	return false;
}

bool isCheckedCommand (const ACHAR *command)
{
	if (!command) return false;
	for (int i = 0; i < commands.length(); i++) {
		// Check as pattern
		if (acutWcMatchEx(command, commands[i], true)) return true;		
	}
	return false;
}

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CDisableCommandsApp : public AcRxArxApp {

public:
	CDisableCommandsApp () : AcRxArxApp () {}

	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
		// TODO: Load dependencies here
        Initialize();
		// You *must* call On_kInitAppMsg here
		AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg (pkt) ;
		pReactor = new CDocReactor(true);
		// TODO: Add your initialization code here
		return (retCode) ;
	}

	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
		// TODO: Add your code here
		if (pReactor) delete pReactor;
		// You *must* call On_kUnloadAppMsg here
		AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg (pkt) ;
		return (retCode) ;
	}

	virtual void RegisterServerComponents () {
	}

} ;

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CDisableCommandsApp)

